package cn.star.jots.preview.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.preview.pojo.dto.PreviewSaveParam;
import cn.star.jots.preview.pojo.vo.PreviewVO;
import cn.star.jots.preview.service.PreviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/preview")
@Api(tags = "预告片管理")
@Slf4j
public class PreviewController {

    @Autowired
    PreviewService previewService;

    @PostMapping("/save")
    @ApiOperation(value = "保存预告片信息")
    public JsonResult save(PreviewSaveParam previewSaveParam){
        log.info("保存预告片信息:previewSaveParam={}", previewSaveParam);
        previewService.save(previewSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("/selectByFilmId/{filmId}")
    @ApiOperation(value = "根据电影id查询预告片信息")
    public JsonResult selectByFilmId(@PathVariable Long filmId){
        log.info("查询预告片信息:filmId={}", filmId);
        List<PreviewVO> list = previewService.selectByFilmId(filmId);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectById/{id}")
    @ApiOperation(value = "查询预告片信息")
    public JsonResult selectById(@PathVariable Long id){
        log.info("查询预告片信息:id={}", id);
        List<PreviewVO> list = previewService.selectById(id);
        return JsonResult.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除预告片信息")
    public JsonResult delete(@PathVariable Long id){
        log.info("删除预告片信息:id={}", id);
        previewService.delete(id);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/film/{filmId}")
    @ApiOperation(value = "取消保存")
    public JsonResult deleteByFilmId(@PathVariable Long filmId){
        log.info("取消保存:filmId={}", filmId);
        previewService.deleteByFilmId(filmId);
        return JsonResult.ok();
    }

    @GetMapping("/select")
    @ApiOperation(value = "查询预告片")
    public JsonResult selectAll(){
        log.info("查询预告片");
        List<PreviewVO> list = previewService.selectAll();
        return JsonResult.ok(list);
    }
}
